﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace CSVExportImport
{
    class Program
    {
        static void Main(string[] args)
        {
            StringReader a = new StringReader("dan,iel, \"po\\\"p,ov\", bla  ");
            ReaderWrapper r = new ReaderWrapper(a);

            Console.WriteLine(r.ReadValue());
            Console.WriteLine(r.ReadValue());
            Console.WriteLine(r.ReadValue());
            Console.WriteLine(r.ReadValue());

            Console.ReadKey();

            Console.WriteLine();

            Processor proc = new Processor();
            proc.AddColumn(new A(1));
            proc.AddColumn(new A(2));
            List<Obj> l = new List<Obj>() { new Obj() { Value = "daniel" }, new Obj() { Value = "popov" } };
            proc.Export(Console.Out, l);


            Console.ReadKey();


            Console.WriteLine();
            Console.WriteLine();

            MemoryStream mem = new MemoryStream();

            StreamWriter writer = new StreamWriter(mem);
            //using (StreamWriter writer = new StreamWriter(mem))
            //{
                proc.Export(writer, l);
                writer.Flush();
            //}
                mem.Position = 0;
            StreamReader reader = new StreamReader(mem);
            var c = proc.Import(reader, () => new Obj());
            Console.WriteLine("length: {0}", c.Count);

            Console.WriteLine();
            Console.WriteLine();

            foreach (var bla in c)
            {
                Console.WriteLine(bla);
            }


            Console.ReadKey();



        }
    }

    public class A : Columns.IColumnTemplate
    {
        int a;
        public A(int a)
        {
            this.a = a;
        }
        #region IColumnTemplate Members

        public string Header
        {
            get
            {
                return "Bla" + a.ToString();
            }
            set
            {
                
            }
        }

        public string GetValue(object obj)
        {
            return ((Obj)obj).Value;
        }

        public void SetValue(object obj, string value)
        {
            ((Obj)obj).Value = value;
            Console.WriteLine("readed: {0}", value);
        }

        #endregion
    }
    public class Obj
    {
        public String Value { get; set; }
        public override string ToString()
        {
            return Value;
        }
    }
}
